<?php
$ip = $_GET['ip'];

$domain = 'http://www.webservicex.net';
$service = '/geoipservice.asmx?WSDL';

$url = $domain.$service;

// Check, whether there is an IP adress given and whether it has at least 7 characters (e.g. 0.0.0.0)
if(strlen($ip)<7) echo "Please define an IP!";


// Create the SoapClient instance
$client     = new SoapClient($url, array("trace" => 1, "exception" => 0));

// Call wsdl function
$result = $client->__soapCall("GetGeoIP", array(
    "GetGeoIP" => array(
        "IPAddress"        => $ip,
    )
));

// Echo the result
$country = $result->GetGeoIPResult->CountryName;

//Build the response xml
header('Content-Type: text/xml');

$xml = '<?xml version="1.0" encoding="utf-8"?>';
$xml .= "<result>";
$xml .= "<countryname>" . $country . "</countryname>";
$xml .= "</result>";

echo $xml;
?>
